elasticsearch

您所在的位置:网站首页 es basic认证 elasticsearch

elasticsearch

#elasticsearch| 来源: 网络整理| 查看: 265

2019年5月21日,Elastic官方发布消息: Elastic Stack 新版本6.8.0 和7.1.0的核心安全功能现免费提供。 这意味着用户现在能够对网络流量进行加密、创建和管理用户、定义能够保护索引和集群级别访问权限的角色,并且使用 Spaces 为 Kibana提供全面保护。 免费提供的核心安全功能如下:

1)TLS 功能。 可对通信进行加密; 2)文件和原生 Realm。 可用于创建和管理用户; 3)基于角色的访问控制。 可用于控制用户对集群 API 和索引的访问权限; 通过针对 Kibana Spaces 的安全功能,还可允许在Kibana 中实现多租户。

1、x-pack演变

1,5.X版本之前:没有x-pack,是独立的:security安全,watch查看,alert警告等独立单元。 2,5.X版本:对原本的安全,警告,监视,图形和报告做了一个封装,形成了x-pack。 3,6.3 版本之前:需要额外安装。 4,6.3版本及之后:已经集成在一起发布,无需额外安装,基础安全属于付费黄金版内容。 7 .1版本:基础安全免费。

2、安全部分免费之前,大家怎么保证基础安全?

场景一:全部“裸奔”,相信这在国内占据了非常大的比重。 内网部署,不对外提供服务。或者ES作为业务基础支撑,不公网开放9200等常用端口,开放的是业务的服务端口。 可能暴露问题:公司或团队内部开放9200、5601端口,基本head插件、kibana都能连接,极易导致线上索引或数据可能被误删。

场景二:加了简单防护。 一般使用Nginx身份认证+防火墙策略控制。

场景三:整合使用了第三方安全认证方案。 比如:SearchGuard、ReadonlyREST。

场景四:付费购买了Elastic-Xpack黄金版或白金版服务。 一般是银行等土豪大客户,对安全、预警、机器学习等付费功能需求迫切,如:宁波银行付费购买白金服务。

以上内容摘自:https://blog.csdn.net/laoyang360/article/details/90554761

既然新版本的es已经提供了基础的用户认证,那么多一层总比没有要强,因此接下来就实际配置一下单机版的elk和集群版的认证,两个稍微有一些不同,因此区分对待。

因为主要体现在es与kibana的认证,因此这里就只展现这两者的配置,其他logstash方面的,后续再完善。

3,单机版elk认证

本次实验elk全系版本都是基于7.4.0进行。

安装过程略过,直接来到配置阶段。

$ cat elasticsearch.yml cluster.name: eryajf-search node.name: es-node1 path.data: /data/elasticsearch7/data path.logs: /data/elasticsearch7/log network.host: 0.0.0.0 http.port: 9200 xpack.security.enabled: true # 这条配置表示开启xpack认证机制 xpack.security.transport.ssl.enabled: true cluster.initial_master_nodes: ["es-node1"] xpack.security.enabled:表示开启xpack认证机制。xpack.security.transport.ssl.enabled:这条如果不配,es将起不来,会报如下错误:Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]

配置完成,记得创建配置中涉及到的目录并授权,然后启动es。启动成功之后,再次访问es,就需要基于用户来访问了,但是在这之前,需要先给对应的用户创建密码才行。

2,为内置账号添加密码

ES中内置了几个管理其他集成组件的账号即:apm_system, beats_system, elastic, kibana, logstash_system, remote_monitoring_user,使用之前,首先需要添加一下密码。

$ /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic] interactive:给用户一一设置密码。auto:自动生成密码。

如果这个地方报如下错误:

Failed to determine the health of the cluster running at http://192.168.3.42:9200 Unexpected response code [503] from calling GET http://192.168.3.42:9200/_cluster/health?pretty Cause: master_not_discovered_exception It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords. It is very likely that the password changes will fail when run against an unhealthy cluster. Do you want to continue with the password setup process [y/N]y

可能是有脏数据导致,此时可以停掉es,删除 data 数据目录,然后重新启动在进行操作。

配置完毕之后,可以通过如下方式访问es服务:

curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty' curl 127.0.0.1:9200 -u elastic 3,配置kibana连接。

开启了安全认证之后,kibana连接es以及访问es都需要认证。

变更kibana的配置,一共有两种方法,一种明文的,一种密文的。

1,明文配置 server.port: 5601 server.host: "0.0.0.0" server.name: "es-node1" elasticsearch.hosts: ["http://192.168.3.42:9200"] kibana.index: ".kibana" i18n.locale: "zh-CN" elasticsearch.username: "kibana" elasticsearch.password: "kibana_passwd" xpack.reporting.encryptionKey: "a_random_string" xpack.security.encryptionKey: "something_at_least_32_characters" elasticsearch.username:连接es的用户名。elasticsearch.password:连接es的密码。xpack.reporting.encryptionKey:如果不添加这条配置,将会报错 Generating a random key for xpack.reporting.encryptionKey. To prevent pending reports from failing on restart, please set xpack.reporting.encryptionKey in kibana.yml。xpack.security.encryptionKey:如果不配置这条,将会报错 Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml。 2,密文配置

当然肯定推荐使用这种密文的方式进行认证,认证之前,需要首先将用户名密码保存到内置的ketstore里。

/usr/share/kibana/bin/kibana-keystore --allow-root create /usr/share/kibana/bin/kibana-keystore --allow-root add elasticsearch.username /usr/share/kibana/bin/kibana-keystore --allow-root add elasticsearch.password

原封不动执行如上三条命令,用户名的时候输入kibana,密码写入对应密码,接着调整kibana的配置:

server.port: 5601 server.host: "0.0.0.0" server.name: "es-node1" elasticsearch.hosts: ["http://192.168.3.42:9200"] kibana.index: ".kibana" i18n.locale: "zh-CN" xpack.reporting.encryptionKey: "a_random_string" xpack.security.encryptionKey: "something_at_least_32_characters"

然后重启kibana即可访问,访问的时候使用elastic的用户密码登入,将是全局管理权限,如果需要创建kibana的只读用户,则可以通过管理–用户–新建用户,对用户进行角色授权即可。

3,logstash配置认证。

打开自定义的logstash的配置文件logstash.conf,在output中增加elasticsearch的用户名和密码

[root@ELK1 ~]# vim /home/elk/logstash-7.2.1/config/logstash.conf input { beats { port => 5044 } } output { stdout { codec => rubydebug } elasticsearch { hosts => ["192.168.3.42:9200"] user => "elastic" password => "123456" } }

 

4,集群配置。

在我配置过程中,发现集群认证需要首先配置秘钥才行,否则在给内置用户创建秘钥的时候将会报错。

1,证书。

如下操作在其中一个node节点执行即可,生成完证书传到集群其他节点即可。

/usr/share/elasticsearch/bin/elasticsearch-certutil ca /usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12

两条命令均一路回车即可,不需要给秘钥再添加密码。

证书创建完成之后,默认在es的数据目录,这里统一放到etc下:

$ ls elastic-* elastic-certificates.p12 elastic-stack-ca.p12 mv elastic-* /etc/elasticsearch/ chown elasticsearch.elasticsearch elastic*

同样,将如上命令生成的两个证书文件拷贝到另外两台机器作为通信依据。

2,配置。

三台机器配置文件如下:

cluster.name: test-search node.name: es-node-1 path.data: /data/elasticsearch/data path.logs: /data/elasticsearch/log network.host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["192.168.3.3:9300","192.168.3.4:9300","192.168.3.5:9300"] cluster.initial_master_nodes: ["192.168.3.3:9300","192.168.3.4:9300","192.168.3.5:9300"] xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: /etc/elasticsearch/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: /etc/elasticsearch/elastic-certificates.p12

除了node.name使用各自主机名之外,其他配置都一样。

如上配置无误,则可以启动es。

3,为内置账号添加密码

ES中内置了几个管理其他集成组件的账号即:apm_system, beats_system, elastic, kibana, logstash_system, remote_monitoring_user,使用之前,首先需要添加一下密码。

$ /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user. You will be prompted to enter passwords as the process progresses. Please confirm that you would like to continue [y/N]y Enter password for [elastic]: Reenter password for [elastic]: Enter password for [apm_system]: Reenter password for [apm_system]: Enter password for [kibana]: Reenter password for [kibana]: Enter password for [logstash_system]: Reenter password for [logstash_system]: Enter password for [beats_system]: Reenter password for [beats_system]: Enter password for [remote_monitoring_user]: Reenter password for [remote_monitoring_user]: Changed password for user [apm_system] Changed password for user [kibana] Changed password for user [logstash_system] Changed password for user [beats_system] Changed password for user [remote_monitoring_user] Changed password for user [elastic] interactive:给用户一一设置密码。auto:自动生成密码。

配置完毕之后,可以通过如下方式访问es服务:

curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty' curl 127.0.0.1:9200 -u elastic

剩下的就是与上边的使用方式一致了,kibana的认证,logstash的认证等等。

其中kibana通过密文认证之后,配置如下:

server.port: 5601 server.host: "0.0.0.0" server.name: "es-node3" elasticsearch.hosts: ["http://192.168.3.3:9208"] kibana.index: ".kibana" i18n.locale: "zh-CN"

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3